<template>
	<view class="tabbar-content">
		<!-- <u-popup v-model="show" mode="bottom" border-radius="14">
			<view class="popup-body">
				<view class="popup-item" @click="navNext('releaseHouse')">
					<image src="../static/image/build.png" mode=""></image>
					<view>发布房屋出租</view>
				</view>
				<view class="popup-item" @click="navNext('releaseCar')">
					<image src="../static/image/icon1.png" mode=""></image>
					<view>发布二手车出售</view>
				</view>
			</view>
		</u-popup> -->
		<u-tabbar v-model="tabbarCurrent" :before-switch="beforeSwitch" mid-button-size='60' :list="tabbarList"
			:mid-button="true"></u-tabbar>
	</view>
</template>

<script>
	import {
		getToken
	} from '@/utils/auth'
	export default {
		data() {
			return {
				tabbarList: [{
						iconPath: "/static/tabbar/index.png",
						selectedIconPath: "/static/tabbar/index_selected.png",
						text: '首页',
						pagePath: '/pages/index/index',
						customIcon: false,
					},
					{
						iconPath: "/static/tabbar/publish2.png",
						selectedIconPath: "/static/tabbar/publish2.png",
						text: '发布',
						// pagePath: '/pages/releaseHouse/index',
						midButton: true,
						customIcon: false,
					},
					{
						iconPath: "/static/tabbar/mine.png",
						selectedIconPath: "/static/tabbar/mine_selected.png",
						text: '我的',
						pagePath: '/pages/mine/index',
						customIcon: false,
					},
				],
				// tabbarCurrent: 1,
				show: false
			}
		},
		props: {
			tabbarCurrent: {
				type: Number,
				default: 1
			}
		},
		methods: {

			beforeSwitch(index) {
				if(this.tabbarCurrent == index){
					return false
				}
				if (index == 1) {
					if (uni.getStorageSync('userInfo').userType != 2) {
						console.log(uni.getStorageSync('userInfo').userType, 'uni');
						uni.showModal({
							title: '提示',
							content: '您不是合作商，不能发布房源！',
							showCancel: false,
							success: function(res) {
								if (res.confirm) {}
							}
						})
						return
					} else {
						let userInfo = uni.getStorageSync('userInfo')
						if (userInfo.phone == '' && userInfo.weChatSignal == '') {
							uni.showModal({
								title: '提示',
								content: '请完善个人信息后再发布！',
								success: function(res) {
									if (res.confirm) {
										uni.navigateTo({
											url: '/pages/personCenter/index'
										})
									} else if (res.cancel) {
										// uni.navigateBack()
									}
								}
							})
							return
						}
						uni.navigateTo({
							url: '/pages/releaseHouse/index'
						})
					}
					return true
				}

				return true
			},
			// navNext(url) {
			// 	if (uni.getStorageSync('userInfo').userType != 2 ) {
			// 		uni.showModal({
			// 			title: '提示',
			// 			content: '您不是合作商，不能发布房源！',
			// 			showCancel: false,
			// 			success: function(res) {
			// 				if (res.confirm) {}
			// 			}
			// 		})
			// 		return
			// 	}
			// 	uni.navigateTo({
			// 		url: `/pages/${url}/index`
			// 	})
			// },
		}
	}
</script>

<style lang="scss">
	.popup-body {
		height: 35vh;
		display: flex;
		justify-content: space-around;
		align-items: center;

		.popup-item {
			text-align: center;

			>image {
				width: 100rpx;
				height: 100rpx;
			}
		}
	}
</style>